package com.yeskery.nut.extend.mcp.server.method;

import com.yeskery.nut.bean.ApplicationContext;
import com.yeskery.nut.extend.mcp.core.Tool;
import com.yeskery.nut.extend.mcp.core.schema.ToolSchema;
import com.yeskery.nut.extend.mcp.server.McpServerCapability;

import java.util.stream.Collectors;

/**
 * 工具列表方法处理器
 * @author sprout
 * 2025-04-17 15:20
 */
public class ToolsListMethodHandler extends BaseListMethodHandler {
    /**
     * 构造工具列表方法处理器
     * @param applicationContext  应用上下文
     * @param mcpServerCapability 服务能力
     */
    public ToolsListMethodHandler(ApplicationContext applicationContext, McpServerCapability mcpServerCapability) {
        super(applicationContext, mcpServerCapability);
    }

    @Override
    protected Object getHandleResult(String cursor) {
        McpServerCapability mcpServerCapability = getMcpServerCapability();
        ToolSchema.ListToolsResult result = new ToolSchema.ListToolsResult();
        result.setTools(mcpServerCapability.getTools().stream().skip(parseNumberCursor(cursor)).map(Tool::getTool).collect(Collectors.toList()));
        return result;
    }
}
